package com.bitcola.security.applications.mapper;

import com.alicp.jetcache.anno.CacheType;
import com.alicp.jetcache.anno.Cached;
import com.bitcola.entity.ColaCoin;
import com.bitcola.entity.ColaMeBalance;
import com.bitcola.entity.ColaSystemBalance;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;
import tk.mybatis.mapper.common.Mapper;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * 用户资金
 */
@Repository
public interface ColaUserBalanceMapper extends Mapper<ColaMeBalance> {


    ColaMeBalance selectBalance(@Param("userid") String userID, @Param("code") String code);
    /**
     * 获取用户币种余额
     *
     * @param userID
     * @param coinCode
     * @return
     */
    BigDecimal getCoinNumber(@Param("userid") String userID, @Param("coincode") String coinCode);


    int addUserBanlance(@Param("userID") String userID, @Param("coinCode") String coinCode, @Param("gain") BigDecimal gain, @Param("key") String balanceKey);

    int reduceUserBanlance(@Param("userID") String userID, @Param("coinCode") String coinCode, @Param("gain") BigDecimal gain, @Param("key") String balanceKey);

    int reduceUserFrozenBanlance(@Param("userID") String userID, @Param("coinCode") String coinCode, @Param("gain") BigDecimal gain, @Param("key") String balanceKey);

    int addUserFrozenBanlance(@Param("userID") String userID, @Param("coinCode") String coinCode, @Param("gain") BigDecimal gain, @Param("key") String balanceKey);
    int changeUserBanlance(@Param("userID") String userID, @Param("coinCode") String coinCode, @Param("balance") BigDecimal balance,
                           @Param("balanceFrozen") BigDecimal balanceFrozen, @Param("prizeBalanceFrozen") BigDecimal prizeBalanceFrozen,
                           @Param("prizeBalanceReleased") BigDecimal prizeBalanceReleased,
                           @Param("applyAmount") BigDecimal applyAmount,
                           @Param("mining") BigDecimal mining,
                           @Param("key") String balanceKey);

    int systemIn(@Param("balance") ColaSystemBalance balance, @Param("key") String balanceKey);

    int systemOut(@Param("balance") ColaSystemBalance balance, @Param("key") String balanceKey);
    int setFrozenBanlanceZero(@Param("userID") String userId, @Param("coinCode") String coinCode, @Param("key") String balanceKey);

    ColaMeBalance getColaToken(@Param("userId") String userId);

    @Cached(key ="#code",expire = 60,cacheType = CacheType.LOCAL)
    ColaCoin getCoin(@Param("code") String code);

    @Cached(key ="#userId",expire = 600,cacheType = CacheType.LOCAL)
    String selectInvitor(@Param("userId") String userId);



    String getMoneyPassword(@Param("id") String userId);

    int setMiningBalance(@Param("id") String id, @Param("value") BigDecimal value);
    List<Map<String ,Object>> queryCom();
}
